package history.hot100.simple;
import history.hot100.ListNode;

// 160. 相交链表:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
public class LeetCode_160 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode head1 = headA;
        ListNode head2 = headB;

        while(head1 != head2) {
            if (head1 != null) head1 = head1.next;
            else head1 = headB;

            if (head2 != null) head2 = head2.next;
            else head2 = headA;
        }
        return head1;
    }
}
